/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * articulos_sie_rep_resxsubfam_inv.java
 *
 * Created on 24/03/2011, 12:34:49 PM
 */

package sie_invdis;



import java.sql.*;
import javax.swing.*;

import javax.swing.JOptionPane;
import javax.swing.JTable;
import javax.swing.JTable.*;
import java.awt.*;
import java.awt.event.*;
import java.util.Date;
import java.util.Calendar;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.text.*;
import javax.swing.JFrame;

import org.jfree.data.category.DefaultCategoryDataset;
import org.jfree.ui.RefineryUtilities;
/**
 *
 * @author Michelle
 */
public class articulos_sie_rep_resxsubfam_inv extends javax.swing.JFrame {



     private javax.swing.table.DefaultTableModel jtable_modelo;
      //private javax.swing.table.DefaultTableModel jtable_tiendas;
      private JTable jtable_tiendas;
      private java.util.Date fechahoy=new Date();
      private int visualisa=0,columnavisualisa=9;
      private String esquesele="all";
      bd_conexion x = new bd_conexion();
      ResultSet rs = null;
      private SimpleDateFormat formateadoresta = new SimpleDateFormat("yyyy-MM-dd");
      private int ordenamiento=2,controlcombo=0;
      

    /** Creates new form articulos_sie_rep_resxsubfam_inv */
    public articulos_sie_rep_resxsubfam_inv() {
         this.iniciar_modelo_de_tabla();
        initComponents();
        // x.estableceConexion();
        this.loadcombo();
         this.setLocation(25,25);
        this.contruir_reporte(ordenamiento,esquesele);
        this.buttonGroup1.setSelected(jrbtn_importe.getModel(), true);
        this.buttonGroup2.setSelected(jrtbn_descripcion.getModel(), true);
        
        jtb_costosxproveedor.getColumnModel().getColumn(0).setPreferredWidth(30);//tem ent
        jtb_costosxproveedor.getColumnModel().getColumn(1).setPreferredWidth(50);//familia
        jtb_costosxproveedor.getColumnModel().getColumn(2).setPreferredWidth(50);//subfam.
        jtb_costosxproveedor.getColumnModel().getColumn(3).setPreferredWidth(70);//id
        jtb_costosxproveedor.getColumnModel().getColumn(4).setPreferredWidth(70);//clave
        jtb_costosxproveedor.getColumnModel().getColumn(5).setPreferredWidth(80);//descrip.
        jtb_costosxproveedor.getColumnModel().getColumn(6).setPreferredWidth(110);//item
        jtb_costosxproveedor.getColumnModel().getColumn(7).setPreferredWidth(70);//precio
        jtb_costosxproveedor.getColumnModel().getColumn(8).setPreferredWidth(30);//f.ult. compra
        jtb_costosxproveedor.getColumnModel().getColumn(9).setPreferredWidth(120);//f.ult. compra

        jtb_costosxproveedor.getTableHeader().setBackground(Color.yellow);
        jtb_costosxproveedor.getTableHeader().setPreferredSize(new Dimension(jtb_costosxproveedor.getTableHeader().getWidth(),60));
        this.jlb_resultado.setText("");
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jPanel2 = new javax.swing.JPanel();
        jbtn_helayudame = new javax.swing.JButton();
        jrbtn_generagrafica = new javax.swing.JRadioButton();
        jPanel3 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jcbx_tiendas = new javax.swing.JComboBox();
        jLabel5 = new javax.swing.JLabel();
        jrbtn_piezas = new javax.swing.JRadioButton();
        jrbtn_importe = new javax.swing.JRadioButton();
        jrbtn_masrentable = new javax.swing.JRadioButton();
        jbtn_generareporte = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtb_costosxproveedor = new javax.swing.JTable()
        {
            public boolean isCellEditable(int rowIndex, int mColIndex) {
                return false;
            }}

            ;
            jLabel7 = new javax.swing.JLabel();
            jlbl_cantidadregistros = new javax.swing.JLabel();
            jLabel6 = new javax.swing.JLabel();
            jrtbn_descripcion = new javax.swing.JRadioButton();
            jLabel13 = new javax.swing.JLabel();
            jtf_buscarenjtable = new javax.swing.JTextField();
            jLabel12 = new javax.swing.JLabel();
            jLabel1 = new javax.swing.JLabel();
            jlb_resultado = new javax.swing.JLabel();
            jMenuBar1 = new javax.swing.JMenuBar();
            jMenu1 = new javax.swing.JMenu();
            jmni_salir = new javax.swing.JMenuItem();
            jMenu2 = new javax.swing.JMenu();
            jmni_escape = new javax.swing.JMenuItem();
            jMenu3 = new javax.swing.JMenu();
            jmni_creacomentario = new javax.swing.JMenuItem();

            setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
            org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sie_invdis.Sie_invdisApp.class).getContext().getResourceMap(articulos_sie_rep_resxsubfam_inv.class);
            setTitle(resourceMap.getString("Form.title")); // NOI18N
            setName("Form"); // NOI18N

            jPanel2.setBorder(javax.swing.BorderFactory.createEtchedBorder());
            jPanel2.setName("jPanel2"); // NOI18N

            jbtn_helayudame.setIcon(resourceMap.getIcon("jbtn_helayudame.icon")); // NOI18N
            jbtn_helayudame.setText(resourceMap.getString("jbtn_helayudame.text")); // NOI18N
            jbtn_helayudame.setName("jbtn_helayudame"); // NOI18N
            jbtn_helayudame.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jbtn_helayudameActionPerformed(evt);
                }
            });

            jrbtn_generagrafica.setText(resourceMap.getString("jrbtn_generagrafica.text")); // NOI18N
            jrbtn_generagrafica.setName("jrbtn_generagrafica"); // NOI18N
            jrbtn_generagrafica.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jrbtn_generagraficaActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
            jPanel2.setLayout(jPanel2Layout);
            jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jrbtn_generagrafica)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 685, Short.MAX_VALUE)
                    .addComponent(jbtn_helayudame)
                    .addContainerGap())
            );
            jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                    .addContainerGap(14, Short.MAX_VALUE)
                    .addComponent(jbtn_helayudame))
                .addGroup(jPanel2Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jrbtn_generagrafica)
                    .addContainerGap(9, Short.MAX_VALUE))
            );

            jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel3.border.title"))); // NOI18N
            jPanel3.setName("jPanel3"); // NOI18N

            jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
            jLabel4.setName("jLabel4"); // NOI18N

            jcbx_tiendas.setToolTipText(resourceMap.getString("jcbx_tiendas.toolTipText")); // NOI18N
            jcbx_tiendas.setName("jcbx_tiendas"); // NOI18N
            jcbx_tiendas.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jcbx_tiendasActionPerformed(evt);
                }
            });

            jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
            jLabel5.setName("jLabel5"); // NOI18N

            buttonGroup1.add(jrbtn_piezas);
            jrbtn_piezas.setText(resourceMap.getString("jrbtn_piezas.text")); // NOI18N
            jrbtn_piezas.setActionCommand(resourceMap.getString("jrbtn_piezas.actionCommand")); // NOI18N
            jrbtn_piezas.setName("jrbtn_piezas"); // NOI18N
            jrbtn_piezas.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jrbtn_piezasActionPerformed(evt);
                }
            });

            buttonGroup1.add(jrbtn_importe);
            jrbtn_importe.setText(resourceMap.getString("jrbtn_importe.text")); // NOI18N
            jrbtn_importe.setActionCommand(resourceMap.getString("jrbtn_importe.actionCommand")); // NOI18N
            jrbtn_importe.setName("jrbtn_importe"); // NOI18N
            jrbtn_importe.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jrbtn_importeActionPerformed(evt);
                }
            });

            buttonGroup1.add(jrbtn_masrentable);
            jrbtn_masrentable.setText(resourceMap.getString("jrbtn_masrentable.text")); // NOI18N
            jrbtn_masrentable.setActionCommand(resourceMap.getString("jrbtn_masrentable.actionCommand")); // NOI18N
            jrbtn_masrentable.setName("jrbtn_masrentable"); // NOI18N
            jrbtn_masrentable.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jrbtn_masrentableActionPerformed(evt);
                }
            });

            jbtn_generareporte.setText(resourceMap.getString("jbtn_generareporte.text")); // NOI18N
            jbtn_generareporte.setToolTipText(resourceMap.getString("jbtn_generareporte.toolTipText")); // NOI18N
            jbtn_generareporte.setName("jbtn_generareporte"); // NOI18N
            jbtn_generareporte.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jbtn_generareporteActionPerformed(evt);
                }
            });

            javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
            jPanel3.setLayout(jPanel3Layout);
            jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addGap(35, 35, 35)
                            .addComponent(jLabel4)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(jcbx_tiendas, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGap(18, 18, 18)
                            .addComponent(jbtn_generareporte, javax.swing.GroupLayout.PREFERRED_SIZE, 133, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGroup(jPanel3Layout.createSequentialGroup()
                            .addComponent(jLabel5)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jrbtn_piezas)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jrbtn_importe)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jrbtn_masrentable)))
                    .addContainerGap(472, Short.MAX_VALUE))
            );
            jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jbtn_generareporte)
                        .addComponent(jcbx_tiendas, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel5)
                        .addComponent(jrbtn_piezas)
                        .addComponent(jrbtn_importe)
                        .addComponent(jrbtn_masrentable)))
            );

            jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder(resourceMap.getString("jPanel4.border.title"))); // NOI18N
            jPanel4.setName("jPanel4"); // NOI18N

            jScrollPane1.setName("jScrollPane1"); // NOI18N

            jtb_costosxproveedor.setModel(this.jtable_modelo);
            jtb_costosxproveedor.setName("jtb_costosxproveedor"); // NOI18N
            jtb_costosxproveedor.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jtb_costosxproveedorMouseClicked(evt);
                    if(evt.getClickCount() >= 2)
                    {
                        dioclick(evt);
                        //System.out.println(" double click" );

                    }
                }
            });
            jScrollPane1.setViewportView(jtb_costosxproveedor);

            jLabel7.setFont(resourceMap.getFont("jLabel7.font")); // NOI18N
            jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
            jLabel7.setName("jLabel7"); // NOI18N

            jlbl_cantidadregistros.setFont(resourceMap.getFont("jlbl_cantidadregistros.font")); // NOI18N
            jlbl_cantidadregistros.setText(resourceMap.getString("jlbl_cantidadregistros.text")); // NOI18N
            jlbl_cantidadregistros.setName("jlbl_cantidadregistros"); // NOI18N

            jLabel6.setFont(resourceMap.getFont("jLabel6.font")); // NOI18N
            jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
            jLabel6.setName("jLabel6"); // NOI18N

            buttonGroup2.add(jrtbn_descripcion);
            jrtbn_descripcion.setText(resourceMap.getString("jrtbn_descripcion.text")); // NOI18N
            jrtbn_descripcion.setActionCommand(resourceMap.getString("jrtbn_descripcion.actionCommand")); // NOI18N
            jrtbn_descripcion.setName("jrtbn_descripcion"); // NOI18N
            jrtbn_descripcion.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jrtbn_descripcionActionPerformed(evt);
                }
            });

            jLabel13.setFont(resourceMap.getFont("jLabel13.font")); // NOI18N
            jLabel13.setText(resourceMap.getString("jLabel13.text")); // NOI18N
            jLabel13.setName("jLabel13"); // NOI18N

            jtf_buscarenjtable.setName("jtf_buscarenjtable"); // NOI18N
            jtf_buscarenjtable.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jtf_buscarenjtableActionPerformed(evt);
                }
            });

            jLabel12.setFont(resourceMap.getFont("jLabel12.font")); // NOI18N
            jLabel12.setText(resourceMap.getString("jLabel12.text")); // NOI18N
            jLabel12.setName("jLabel12"); // NOI18N

            jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
            jLabel1.setName("jLabel1"); // NOI18N

            jlb_resultado.setFont(resourceMap.getFont("jlb_resultado.font")); // NOI18N
            jlb_resultado.setText(resourceMap.getString("jlb_resultado.text")); // NOI18N
            jlb_resultado.setName("jlb_resultado"); // NOI18N

            javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
            jPanel4.setLayout(jPanel4Layout);
            jPanel4Layout.setHorizontalGroup(
                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addGap(87, 87, 87)
                    .addComponent(jLabel7)
                    .addGap(18, 18, 18)
                    .addComponent(jlbl_cantidadregistros, javax.swing.GroupLayout.PREFERRED_SIZE, 39, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jLabel6)
                    .addContainerGap(630, Short.MAX_VALUE))
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                    .addContainerGap()
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 885, Short.MAX_VALUE))
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addGap(19, 19, 19)
                    .addComponent(jLabel1)
                    .addGap(85, 85, 85)
                    .addComponent(jLabel12)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jrtbn_descripcion)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jLabel13)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jtf_buscarenjtable, javax.swing.GroupLayout.PREFERRED_SIZE, 147, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(55, 55, 55)
                    .addComponent(jlb_resultado, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(25, Short.MAX_VALUE))
            );
            jPanel4Layout.setVerticalGroup(
                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel4Layout.createSequentialGroup()
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel6)
                        .addComponent(jlbl_cantidadregistros)
                        .addComponent(jLabel7))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 354, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(18, 18, 18)
                    .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel12)
                        .addComponent(jrtbn_descripcion, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel13)
                        .addComponent(jtf_buscarenjtable, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel1)
                        .addComponent(jlb_resultado))
                    .addContainerGap(14, Short.MAX_VALUE))
            );

            jMenuBar1.setName("jMenuBar1"); // NOI18N

            jMenu1.setText(resourceMap.getString("jMenu1.text")); // NOI18N
            jMenu1.setName("jMenu1"); // NOI18N

            jmni_salir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.ALT_MASK));
            jmni_salir.setIcon(resourceMap.getIcon("jmni_salir.icon")); // NOI18N
            jmni_salir.setText(resourceMap.getString("jmni_salir.text")); // NOI18N
            jmni_salir.setName("jmni_salir"); // NOI18N
            jmni_salir.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jmni_salirActionPerformed(evt);
                }
            });
            jMenu1.add(jmni_salir);

            jMenuBar1.add(jMenu1);

            jMenu2.setText(resourceMap.getString("jMenu2.text")); // NOI18N
            jMenu2.setName("jMenu2"); // NOI18N

            jmni_escape.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ESCAPE, 0));
            jmni_escape.setText(resourceMap.getString("jmni_escape.text")); // NOI18N
            jmni_escape.setName("jmni_escape"); // NOI18N
            jmni_escape.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jmni_escapeActionPerformed(evt);
                }
            });
            jMenu2.add(jmni_escape);

            jMenuBar1.add(jMenu2);

            jMenu3.setText(resourceMap.getString("jMenu3.text")); // NOI18N
            jMenu3.setName("jMenu3"); // NOI18N

            jmni_creacomentario.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_U, java.awt.event.InputEvent.ALT_MASK));
            jmni_creacomentario.setText(resourceMap.getString("jmni_creacomentario.text")); // NOI18N
            jmni_creacomentario.setName("jmni_creacomentario"); // NOI18N
            jmni_creacomentario.addActionListener(new java.awt.event.ActionListener() {
                public void actionPerformed(java.awt.event.ActionEvent evt) {
                    jmni_creacomentarioActionPerformed(evt);
                }
            });
            jMenu3.add(jmni_creacomentario);

            jMenuBar1.add(jMenu3);

            setJMenuBar(jMenuBar1);

            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
            );

            pack();
        }// </editor-fold>//GEN-END:initComponents

    private void jbtn_helayudameActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_helayudameActionPerformed
        // TODO add your handling code here:
        this.ayuda();
}//GEN-LAST:event_jbtn_helayudameActionPerformed

    private void jcbx_tiendasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jcbx_tiendasActionPerformed
        // TODO add your handling code here:
        int indeceta=this.jcbx_tiendas.getSelectedIndex();

        if (indeceta > 0 ) {
            indeceta=indeceta-1;
            esquesele=jtable_tiendas.getValueAt(indeceta, 2).toString();
            System.out.println(esquesele);
            controlcombo=1;
            this.jbtn_generareporteActionPerformed(evt);
        } else {
            System.out.println("entro");
            if (controlcombo > 0 ) {
                esquesele="all";
                this.jbtn_generareporteActionPerformed(evt);
                controlcombo=0;
            }
        }


        //this.jtfpruebados.setText(jtable_tiendas.getValueAt(indeceta, 0).toString());
}//GEN-LAST:event_jcbx_tiendasActionPerformed
    private void loadcombo(){
        jtable_tiendas=variables_global.gettabla_tiendas();
         int numerotiendas=this.jtable_tiendas.getRowCount();
         this.jcbx_tiendas.addItem("Todas Las Tiendas");
          for(int ii=0;ii<numerotiendas;ii++)
                {
                    this.jcbx_tiendas.addItem(jtable_tiendas.getValueAt(ii, 0));
                }
    }
    private void jrbtn_piezasActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbtn_piezasActionPerformed
        // TODO add your handling code here:
        ordenamiento=Integer.parseInt(evt.getActionCommand().toString());
}//GEN-LAST:event_jrbtn_piezasActionPerformed

    private void jrbtn_importeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbtn_importeActionPerformed
        // TODO add your handling code here:
        ordenamiento=Integer.parseInt(evt.getActionCommand().toString());
}//GEN-LAST:event_jrbtn_importeActionPerformed

    private void jrbtn_masrentableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbtn_masrentableActionPerformed
        // TODO add your handling code here:
        ordenamiento=Integer.parseInt(evt.getActionCommand().toString());
}//GEN-LAST:event_jrbtn_masrentableActionPerformed

    private void jbtn_generareporteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtn_generareporteActionPerformed
        // TODO add your handling code here:
        if(JOptionPane.showConfirmDialog(null, "Estan Correctos sus Datos?")==0) {

           this.contruir_reporte(ordenamiento,esquesele);
        }


    }//GEN-LAST:event_jbtn_generareporteActionPerformed

    private void jmni_salirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_salirActionPerformed
        // TODO add your handling code here:
        this.dispose();
    }//GEN-LAST:event_jmni_salirActionPerformed


private void jtb_costosxproveedorMouseClicked(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:
    }

    private void jrbtn_generagraficaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbtn_generagraficaActionPerformed
        // TODO add your handling code here:
        System.out.println("se crea nuevo:");
        ventas_sie_cortes_graficacion demo1rixs = new ventas_sie_cortes_graficacion("Sistema Integral: Resumen inventarios X Familia",7);
        demo1rixs.pack();
        RefineryUtilities.centerFrameOnScreen(demo1rixs);
        demo1rixs.setVisible(true);
}//GEN-LAST:event_jrbtn_generagraficaActionPerformed

    private void jmni_creacomentarioActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_creacomentarioActionPerformed
        // TODO add your handling code here:
        this.crearcomentario();
    }//GEN-LAST:event_jmni_creacomentarioActionPerformed

    private void jmni_escapeActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jmni_escapeActionPerformed
        // TODO add your handling code here:
        this.jmni_salirActionPerformed(evt);
    }//GEN-LAST:event_jmni_escapeActionPerformed

    private void jrtbn_descripcionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrtbn_descripcionActionPerformed
        // TODO add your handling code here:
        columnavisualisa=Integer.parseInt(evt.getActionCommand().toString());
}//GEN-LAST:event_jrtbn_descripcionActionPerformed

    private void jtf_buscarenjtableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jtf_buscarenjtableActionPerformed
        // TODO add your handling code here:
        this.find_textoenjtable(columnavisualisa, 0, this.jtf_buscarenjtable.getText().toUpperCase().trim());
}//GEN-LAST:event_jtf_buscarenjtableActionPerformed

    private void dioclick(java.awt.event.MouseEvent evt) {
        // TODO add your handling code here:

         System.out.println("dio doble  click");
              
                int fila = jtb_costosxproveedor.getSelectedRow();

                Object valorfolio = jtb_costosxproveedor.getValueAt(fila, 9);
                String arreglo_codigo[]=valorfolio.toString().split(":");
                articulos_sie_rep_resxsubfam_detalle repressubdet = new articulos_sie_rep_resxsubfam_detalle(Integer.valueOf(arreglo_codigo[0]),arreglo_codigo[1]);
                repressubdet.pack();
                repressubdet.setVisible(true);



        //setVisible(false);
    }


    private  void ayuda()
            {
                String punto1="1.- Este Reporte muestra Ventas Por Proveedor en un rango de Fechas determinado \n";
                String punto2="2.- Cada Boton tiene Una letra Resaltada el cual indica su metodo abreviado, uselo si desea mayor rapides ( ejemplo Alt+a obtendra ayuda automaticamente)\n";
                String punto3="3.- Algunos Reportes pueden tardar Unos minutos dependiento del rango de Fechas seleccionadas. \n ";
                String punto4="4.- Pase el Puntero del Mause sobre el Elemento este le mostrara una pequeña descripcion de lo qu hace. \n ";
                JOptionPane.showMessageDialog(null,""+punto1+punto2+punto3+punto4+"", "Sistema Integral(Reporte Ventas por Proveedor) : Ayuda",1);
            }
private void iniciar_modelo_de_tabla()
    {

        jtable_modelo=new javax.swing.table.DefaultTableModel();//Creo el modelo
        jtable_modelo.addColumn("<html><b>Lugar</b></html>");
        jtable_modelo.addColumn("<html><b>Existencias Actuales</b></html>");
        jtable_modelo.addColumn("<html><b>Costos Actual</b></html>");
        jtable_modelo.addColumn("<html><b>Acum. Piezas Vendidas</b></html>");
        jtable_modelo.addColumn("<html><b>Costo de Lo Vendido</b></html>");
        jtable_modelo.addColumn("<html><b>Acum. Venta Precio Publico</b></html>");
        jtable_modelo.addColumn("<html><b>% Rotacion costo Actual <br> VS Costo Vendido</b></html>");
        jtable_modelo.addColumn("<html><b>% Aportado Costo Total</b></html>");
        jtable_modelo.addColumn("<html><b>% Acum.</b></html>");
        jtable_modelo.addColumn("<html><b>Subfamilia</b></html>");



   }
void LimpiarJTable()
    {
     //limpiar la tabla
        while(jtable_modelo.getRowCount()>0)jtable_modelo.removeRow(0);
    }
private void contruir_reporte(int ordena,String idesq)
    {
        //fecha es la final del reporte
         DefaultCategoryDataset dataset = new DefaultCategoryDataset();//detalle por tienda
         String titulografico="",titulograficoh="",ti="";

        LimpiarJTable();//limpio si existen Registros
        DecimalFormat miformat = new DecimalFormat("###,###,###,###");

        DecimalFormat miformat2 = new DecimalFormat("###,###,###,###.#");
        int ii=0,idtienda=0,ndias=0,reg=0,noaten=0;
        //indicamos 7 columnas
        Object valtie = null;
        String serie1="",tienda="";

        SimpleDateFormat formato = new SimpleDateFormat("yyyy-MM-dd");


        float importe=0,totalpiezas=0,totcosto=0,totutili=0,totporcen=0,totporcenacum=0,importe2=0,importe3=0,costocompras=0,piezas2=0;
        int rankin=0;
        //Voy por la venta del dia


        //serie1 = this.fechaeuropea(fechai)+" AL "+this.fechaeuropea(fecha);//fecha final de reporte


               try{
                 //rs = x.sieuno_ventas_cortedia(tienda,pFecha,i);
                 rs=x.sieuno_executediversosv2("select * from x1sieuno_articulo_costosxproveedor('"+idesq+"',"+ordena+") as (id integer, can double precision,cos double precision,canproducto real,importecosto double precision,importeneto double precision,nom character varying(50));",variables_global.getconexiongral());
                 while (rs.next())
                        {
                            rankin++;
                            totalpiezas+=rs.getFloat(2);
                            importe+=rs.getFloat(3);
                            piezas2+=rs.getFloat(4);
                            totcosto+=rs.getFloat(5);
                            totutili+=rs.getFloat(6);

                            costocompras=+rs.getFloat(3)+rs.getFloat(5);
                            jtable_modelo.addRow(new Object[]{rankin,miformat.format(rs.getFloat(2)),miformat.format(rs.getFloat(3)),miformat.format(rs.getFloat(4)),miformat.format(rs.getFloat(5)),miformat.format(rs.getFloat(6)),miformat.format((rs.getFloat(5)/costocompras)*100)+"%",0,0,rs.getString (1)+":"+rs.getString (7)});
                        }
                    }
                     catch(Exception e)
                     {
                             System.out.println(e.getMessage());
                     }

            jtable_modelo.addRow(new Object[]{"<html><h3><b>Totales: "+"</b></h3></html>","<html><h3><b>"+miformat.format(totalpiezas)+"</b></h3></html>","<html><h3><b>"+miformat.format(importe)+"</b></h3></html>","<html><h3><b>"+miformat.format(piezas2)+"</b></h3></html>","<html><h3><b>"+miformat.format(totcosto)+"</b></h3></html>","<html><h3><b>"+miformat.format(totutili)+"</b></h3></html>","<html><h3><b>"+miformat.format((totcosto/costocompras)*100)+"</b></h3></html>",0,0,""});
             
            titulografico="Resumen Inventarios X Subfamilia al: "+this.fechaeuropea(fechahoy)+ " Total="+miformat.format(importe)+"";

            variables_global.settitulografica_artmasvxp(titulografico);

            int numerofilas=this.jtable_modelo.getRowCount()-1;
             rankin=0;
             for(int i = 0 ;i < numerofilas; i++)
                {
                 valtie=this.jtable_modelo.getValueAt(i,3);
                 serie1=this.jtable_modelo.getValueAt(i,1).toString();

                 importe2=Float.valueOf(valtie.toString().replace(",","").replace(".",""));
                 totporcen=(Float.valueOf(valtie.toString().replace(",","").replace(".",""))/importe)*100;
                 totporcenacum+=totporcen;
                 jtable_modelo.setValueAt(miformat2.format(totporcen)+"%",i,8);
                 jtable_modelo.setValueAt(miformat.format(totporcenacum)+"%",i,9);
                 if (serie1.length()>12)
                        {
                            serie1=serie1.substring(0, 12);
                        }

                 if(totporcenacum < 70)
                        {
                            dataset.addValue(importe2,this.jtable_modelo.getValueAt(i,0).toString()+"="+serie1,"Sub Familias");
                             rankin++;
                        }
                 else
                        {
                            importe3+=importe2;
                        }
                 }
                 dataset.addValue(importe3, rankin+" sub Familias 30% Restantes","Sub Familias");

                 variables_global.setdatasetresxprov(dataset);
                 this.registrosobtenidos();
 }
private String  fechaeuropea(Date fecha) {
       SimpleDateFormat formateadorestaeuropa = new SimpleDateFormat("dd-MM-yyyy");
       String cadenafecha="";

       cadenafecha= formateadorestaeuropa.format(fecha);
       return cadenafecha;

    }

private void crearcomentario()
          {
                 String retorno="";

        String comentario=JOptionPane.showInputDialog("Ingresa Tu Sugerencia o Comentario:");
        if (comentario.length()>0)
        {
            rs = x.sieuno_executediversosv2("select * from x1distribucion_bitacorainserta('"+comentario+"', 'Rep Resumen Inve x subfam');",variables_global.getconexiongral());
            try
            {

               while (rs.next())
                    {
                         retorno=rs.getString(1);
                   }
             }
            catch(Exception e)
            {
                System.out.println(e.getMessage());
            }
            if (retorno.equals("1"))
              {
                JOptionPane.showMessageDialog(null,"Gracias Tu comentario ha sido guardado", "Sistema Integral Comentarios",1);

              }

      }
    }

void registrosobtenidos()
 {
     //limpiar la tabla
    this.jlbl_cantidadregistros.setText(String.valueOf(this.jtable_modelo.getRowCount()));

 }
private void find_textoenjtable(int columna,int filainicio,String texto)
    {

       int totalfilasreporte=this.jtable_modelo.getRowCount(),i=0,encontro=0,coincidencias=0;

       String cadenaobtenida="";
         //genero los totales por tienda

       for(i=0;i<totalfilasreporte;i++)
            {
                cadenaobtenida=jtable_modelo.getValueAt(i, columna).toString();
                encontro=cadenaobtenida.indexOf(texto);
                if(encontro!=-1)
                    {
                        System.out.println(cadenaobtenida+" en pocicion "+i);
                        this.jtb_costosxproveedor.changeSelection(i, 0, true, false);
                        encontro=-1;
                        coincidencias++;
                    }
            }

       this.jlb_resultado.setText("Resultado:"+this.jtf_buscarenjtable.getText()+"="+coincidencias);
    }

    /**
    * @param args the command line arguments
    */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
                new articulos_sie_rep_resxsubfam_inv().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel13;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JButton jbtn_generareporte;
    private javax.swing.JButton jbtn_helayudame;
    private javax.swing.JComboBox jcbx_tiendas;
    private javax.swing.JLabel jlb_resultado;
    private javax.swing.JLabel jlbl_cantidadregistros;
    private javax.swing.JMenuItem jmni_creacomentario;
    private javax.swing.JMenuItem jmni_escape;
    private javax.swing.JMenuItem jmni_salir;
    private javax.swing.JRadioButton jrbtn_generagrafica;
    private javax.swing.JRadioButton jrbtn_importe;
    private javax.swing.JRadioButton jrbtn_masrentable;
    private javax.swing.JRadioButton jrbtn_piezas;
    private javax.swing.JRadioButton jrtbn_descripcion;
    private javax.swing.JTable jtb_costosxproveedor;
    private javax.swing.JTextField jtf_buscarenjtable;
    // End of variables declaration//GEN-END:variables

}
